using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace Medianamik.Core.DAL.SubSonicDAL
{
	/// <summary>
	/// Strongly-typed collection for the Culture class.
	/// </summary>
    [Serializable]
	public partial class CultureCollection : ActiveList<Culture, CultureCollection>
	{	   
		public CultureCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>CultureCollection</returns>
		public CultureCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                Culture o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the medianamik_Culture table.
	/// </summary>
	[Serializable]
	public partial class Culture : ActiveRecord<Culture>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Culture()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public Culture(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public Culture(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public Culture(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("medianamik_Culture", TableType.Table, DataService.GetInstance("MedianamikProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarCultureName = new TableSchema.TableColumn(schema);
				colvarCultureName.ColumnName = "CultureName";
				colvarCultureName.DataType = DbType.String;
				colvarCultureName.MaxLength = 10;
				colvarCultureName.AutoIncrement = false;
				colvarCultureName.IsNullable = false;
				colvarCultureName.IsPrimaryKey = true;
				colvarCultureName.IsForeignKey = false;
				colvarCultureName.IsReadOnly = false;
				colvarCultureName.DefaultSetting = @"";
				colvarCultureName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCultureName);
				
				TableSchema.TableColumn colvarContentManagementActive = new TableSchema.TableColumn(schema);
				colvarContentManagementActive.ColumnName = "ContentManagementActive";
				colvarContentManagementActive.DataType = DbType.Boolean;
				colvarContentManagementActive.MaxLength = 0;
				colvarContentManagementActive.AutoIncrement = false;
				colvarContentManagementActive.IsNullable = true;
				colvarContentManagementActive.IsPrimaryKey = false;
				colvarContentManagementActive.IsForeignKey = false;
				colvarContentManagementActive.IsReadOnly = false;
				colvarContentManagementActive.DefaultSetting = @"";
				colvarContentManagementActive.ForeignKeyTableName = "";
				schema.Columns.Add(colvarContentManagementActive);
				
				TableSchema.TableColumn colvarMedianamikActive = new TableSchema.TableColumn(schema);
				colvarMedianamikActive.ColumnName = "MedianamikActive";
				colvarMedianamikActive.DataType = DbType.Boolean;
				colvarMedianamikActive.MaxLength = 0;
				colvarMedianamikActive.AutoIncrement = false;
				colvarMedianamikActive.IsNullable = true;
				colvarMedianamikActive.IsPrimaryKey = false;
				colvarMedianamikActive.IsForeignKey = false;
				colvarMedianamikActive.IsReadOnly = false;
				colvarMedianamikActive.DefaultSetting = @"";
				colvarMedianamikActive.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMedianamikActive);
				
				TableSchema.TableColumn colvarPosition = new TableSchema.TableColumn(schema);
				colvarPosition.ColumnName = "Position";
				colvarPosition.DataType = DbType.Int16;
				colvarPosition.MaxLength = 0;
				colvarPosition.AutoIncrement = false;
				colvarPosition.IsNullable = false;
				colvarPosition.IsPrimaryKey = false;
				colvarPosition.IsForeignKey = false;
				colvarPosition.IsReadOnly = false;
				colvarPosition.DefaultSetting = @"";
				colvarPosition.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPosition);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MedianamikProvider"].AddSchema("medianamik_Culture",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("CultureName")]
		[Bindable(true)]
		public string CultureName 
		{
			get { return GetColumnValue<string>(Columns.CultureName); }
			set { SetColumnValue(Columns.CultureName, value); }
		}
		  
		[XmlAttribute("ContentManagementActive")]
		[Bindable(true)]
		public bool? ContentManagementActive 
		{
			get { return GetColumnValue<bool?>(Columns.ContentManagementActive); }
			set { SetColumnValue(Columns.ContentManagementActive, value); }
		}
		  
		[XmlAttribute("MedianamikActive")]
		[Bindable(true)]
		public bool? MedianamikActive 
		{
			get { return GetColumnValue<bool?>(Columns.MedianamikActive); }
			set { SetColumnValue(Columns.MedianamikActive, value); }
		}
		  
		[XmlAttribute("Position")]
		[Bindable(true)]
		public short Position 
		{
			get { return GetColumnValue<short>(Columns.Position); }
			set { SetColumnValue(Columns.Position, value); }
		}
		
		#endregion
		
		
		#region PrimaryKey Methods		
		
        protected override void SetPrimaryKey(object oValue)
        {
            base.SetPrimaryKey(oValue);
            
            SetPKValues();
        }
        
		
		private Medianamik.Core.DAL.SubSonicDAL.NodeInstanceCollection colNodeInstanceRecords;
		public Medianamik.Core.DAL.SubSonicDAL.NodeInstanceCollection NodeInstanceRecords()
		{
			if(colNodeInstanceRecords == null)
			{
				colNodeInstanceRecords = new Medianamik.Core.DAL.SubSonicDAL.NodeInstanceCollection().Where(NodeInstance.Columns.CultureName, CultureName).Load();
				colNodeInstanceRecords.ListChanged += new ListChangedEventHandler(colNodeInstanceRecords_ListChanged);
			}
			return colNodeInstanceRecords;
		}
				
		void colNodeInstanceRecords_ListChanged(object sender, ListChangedEventArgs e)
		{
            if (e.ListChangedType == ListChangedType.ItemAdded)
            {
		        // Set foreign key value
		        colNodeInstanceRecords[e.NewIndex].CultureName = CultureName;
				colNodeInstanceRecords.ListChanged += new ListChangedEventHandler(colNodeInstanceRecords_ListChanged);
            }
		}
		#endregion
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varCultureName,bool? varContentManagementActive,bool? varMedianamikActive,short varPosition)
		{
			Culture item = new Culture();
			
			item.CultureName = varCultureName;
			
			item.ContentManagementActive = varContentManagementActive;
			
			item.MedianamikActive = varMedianamikActive;
			
			item.Position = varPosition;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(string varCultureName,bool? varContentManagementActive,bool? varMedianamikActive,short varPosition)
		{
			Culture item = new Culture();
			
				item.CultureName = varCultureName;
			
				item.ContentManagementActive = varContentManagementActive;
			
				item.MedianamikActive = varMedianamikActive;
			
				item.Position = varPosition;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn CultureNameColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn ContentManagementActiveColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn MedianamikActiveColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn PositionColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string CultureName = @"CultureName";
			 public static string ContentManagementActive = @"ContentManagementActive";
			 public static string MedianamikActive = @"MedianamikActive";
			 public static string Position = @"Position";
						
		}
		#endregion
		
		#region Update PK Collections
		
        public void SetPKValues()
        {
                if (colNodeInstanceRecords != null)
                {
                    foreach (Medianamik.Core.DAL.SubSonicDAL.NodeInstance item in colNodeInstanceRecords)
                    {
                        if (item.CultureName != CultureName)
                        {
                            item.CultureName = CultureName;
                        }
                    }
               }
		}
        #endregion
    
        #region Deep Save
		
        public void DeepSave()
        {
            Save();
            
                if (colNodeInstanceRecords != null)
                {
                    colNodeInstanceRecords.SaveAll();
               }
		}
        #endregion
	}
}
